package ae.pcfc.cldos.online.web.controller.client.company.financial;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import ae.pcfc.cldos.online.common.delegate.CompanyInformationDelegate;
import ae.pcfc.cldos.online.common.exception.FNPAppException;
import ae.pcfc.cldos.online.common.exception.GSAppException;
import ae.pcfc.cldos.online.common.exception.NoSuchCompanyException;
import ae.pcfc.cldos.online.common.vo.CompanyInformationVO;
import ae.pcfc.cldos.online.web.ViewPath;
import ae.pcfc.cldos.online.web.controller.base.BasePageController;
import ae.pcfc.cldos.online.web.model.CompanyInformationModel;

/**
 * Controller that handles all {@link Company}-related requests, i.e.: all
 * requests for /company/register/nonclient/
 * 
 * @author Abdullah
 */
@Controller
@RequestMapping(value = ViewPath.__COMPANY_FINANCIAL_INFO)
public class CompanyFinancialController extends BasePageController {
	
	@Autowired
	@Qualifier("companyInformationDelegate")
	private CompanyInformationDelegate companyInformationDelegate;
	
	
	@ModelAttribute
	public void populateBreadCrumbs(ModelMap model) {
		breadCrumbsFactoryService.populateFinancialData(model);
	}

	@ModelAttribute("CompanyInformationInfo")
	public CompanyInformationModel populateCompanyInformationInfoModel(HttpServletRequest request) {
		CompanyInformationModel companyInformationModel = new CompanyInformationModel();
		CompanyInformationVO companyInformationVO=null;
		try{
			companyInformationVO = companyInformationDelegate.retriveGSInformation(getUserVO());
			mapper.map(companyInformationVO, companyInformationModel);
		}catch(NoSuchCompanyException e){
			companyInformationModel.setCompanyError(true);
		}catch(GSAppException e){
			companyInformationModel.setGsError(true);
		}
		try{
			companyInformationVO = companyInformationDelegate.retriveFNPInformation(getUserVO());
			companyInformationModel.setPrepaidAccBalance(new Double(companyInformationVO.getPrepaidAccBalance()).toString());
			companyInformationModel.setReservedAccBalance(new Double(companyInformationVO.getReservedAccBalance()).toString());
		}catch(NoSuchCompanyException e){
			companyInformationModel.setCompanyError(true);
		}catch(FNPAppException e){
			companyInformationModel.setFnpError(true);
		}
		return companyInformationModel;
	}
	
	@RequestMapping(value = "/show.htm", method = RequestMethod.GET)
	public void show(){
		
	}


}
